import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;


class Count{
    public static int count;
    public static void add(){
        count++;
    }
}
public class ThreadDemo2 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Count count1=new Count();
        //Callable其实跟Runnable一样是放任务的，但是区别就是Callable就是具有返回值

        Callable<Integer> callable=new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                for (int i = 0; i < 500; i++) {
                    Count.add();
                }
                return Count.count;
            }
        };

        //这个是包装任务的
        FutureTask<Integer> futureTask=new FutureTask<>(callable);

        Thread thread=new Thread(futureTask);
        thread.start();
        int a=futureTask.get();
        System.out.println(a);
    }
}
